#pragma once
#include "util.h"
#include <fstream>
/**
* Base class for writing binary files.
* @author Koen Samyn
*/
class BinaryWriter
{
public:
	/**
	* Creates an empty BinaryWriter object.
	*/
	BinaryWriter();
	/**
	* Creates a new BinaryWriter object.
	* @param filename the name of the file to write.
	*/
	BinaryWriter(tstring filename);
	/**
	* Destroys the BinaryWriter object.
	*/
	virtual ~BinaryWriter(void);
	/**
	* Write the file.
	* @return true if writing the file was succesful, false otherwise.
	*/
	bool Open();
	/**
	* Closes the file.
	* 
	*/
	void Close();
	/**
	* Gets the filename to write.
	* @return the filename to write.
	*/
	const tstring& GetFileName() const{
		return m_FileName;
	}
	/**
	* Sets the filename to write to.
	* @param filename the filename to write to.
	*/
	void SetFileName(tstring fileName){
		m_FileName= fileName;
	}

	/**
	* Writes a tstring to the stream.
	* @param string the string to write.
	*/
	void WriteString(tstring& string);

	/**
	* Checks if the file is open for writing.
	* @return true if the file is open, false otherwise.
	*/
	bool IsOpen(){
		return m_Open;
	}

protected:
	/**
	* indicates that the file is open for writing.
	*/
	bool m_Open;
	/**
	* The output stream
	*/
	fstream m_Output;
private:
	/**
	* The name of the file to write.
	*/
	tstring m_FileName;
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------
	BinaryWriter(const BinaryWriter& t);
	BinaryWriter& operator=(const BinaryWriter& t);
};
